package com.at.abc.r421_e;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class c {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(br.readLine());
        char[] s = br.readLine().toCharArray();

        List<Integer> A = new ArrayList<>();
        List<Integer> B = new ArrayList<>();

        for (int i = 0; i < 2 * n; i++) {
            if (s[i] == 'A') {
                A.add(i);
            } else {
                B.add(i);
            }
        }

        long cost1 = 0;
        // ABAB
        for (int i = 0; i < n; i++) {
            int targetPos = 2 * i;
            cost1 += Math.abs(A.get(i) - targetPos);
        }

        // BABA
        long cost2 = 0;
        for (int i = 0; i < n; i++) {
            int targetPos = 2 * i + 1;
            cost2 += Math.abs(A.get(i) - targetPos);
        }

        out.println(Math.min(cost1, cost2));

        out.flush();
        out.close();
        br.close();
    }

}
